package com.edgclub.edg.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.edgclub.edg.R;
import com.edgclub.edg.activity.GroupDetailsActivity;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;
import com.hyphenate.easeui.model.GroupChatBean;
import com.rockerhieu.emojicon.EmojiconTextView1;

import java.util.ArrayList;
import java.util.List;

public class OtherUserGroupAdapter extends BaseAdapter{
    private Context mContext;
    private List<GroupChatBean>list;
    GlideUtils glideUtils=new GlideUtils();
    public OtherUserGroupAdapter(Context Context) {
        super();
        mContext = Context;
    }

    public void setList(List<GroupChatBean> list) {
        this.list = list;
        if(null==this.list)this.list=new ArrayList<>();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_othre_group, null);
            holder = new ViewHolder();
            holder.icon_iv = (ImageView) convertView.findViewById(R.id.icon_iv_top);
            holder.group_name = (EmojiconTextView1) convertView.findViewById(R.id.group_name);
            holder.group_details = (EmojiconTextView1) convertView.findViewById(R.id.group_details);

            convertView.setTag(R.id.tag_first,holder);
        }else {
            holder = (ViewHolder) convertView.getTag(R.id.tag_first);
        }
        holder.group_name.setText(list.get(position).getGname());
        holder.group_details.setText(list.get(position).getRemark());
        glideUtils.Glidde_loadRoudImage(mContext, list.get(position).getLogo(), holder.icon_iv, 10);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, GroupDetailsActivity.class);
                intent.putExtra("groupid",list.get(position).getGroupid());
                intent.putExtra("groupname",list.get(position).getGname());
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }
    class ViewHolder {
        private ImageView icon_iv;
        private EmojiconTextView1 group_name;
        private EmojiconTextView1 group_details;
    }
}
